/**
 * @author 徐楠
 * @date 2022/1/12 18:44
 * @version 1.0
 */

package com.xunan.likou;

import java.util.ArrayList;
import java.util.List;

public class MissingNumber {
    public static void main(String[] args) {
        int[] nums = { 9,6,4,2,3,5,7,0,1};
        int result = missingNumber(nums);
        System.out.println(result);
    }

    public static int missingNumber(int[] nums) {

        List<Integer> list = new ArrayList<>();
        int max = -1;
        for (int num : nums) {
            list.add(num);
            if (num > max) {
                max = num;
            }
        }
        for (int i = 0; i < max; i++) {
            if (!list.contains(i)) {
                return i;
            }
        }


        return max + 1;
    }
}
